<?php

Class Oracle{
 var $pdo;
 var $connect_id;
 function __construct($host,$login,$pass, $db){
	//$link = mysql_connect($host, $login, $pass);
	//if (!$link) {
	//	die('Could not connect: ' . mysql_error());
	//}
	//mysql_select_db($db);
	
	/*$tns = "  
		(DESCRIPTION =
			(ADDRESS_LIST =
			  (ADDRESS = (PROTOCOL = TCP)(HOST = ".$host.")(PORT = 1521))
			)
			(CONNECT_DATA =
			  (SID=orcl)
			)
		  )
       ";
	try{
		$this->pdo = new PDO ("oci:dbname=$tns","$login","$pass");
	}catch (PDOException $e) {
		echo "Failed to get DB handle: " . $e->getMessage() . "\n";
    exit;
	}
			*/
		$db = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
		(HOST=217.173.198.132) (PORT=1521))) (CONNECT_DATA=(SID=orcl)))";

		$conn = ocilogon($login, $pass, $db);
		if ($conn){ echo "SUKCES - POLACZONO Z ORACLE\n";}
		else{$err= OCIError();	echo "BLAD POLACZENIA". $ERR[text];	}

	/*
	$db = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
	(HOST=217.173.198.132) (PORT=1521))) (CONNECT_DATA=(SID=orcl)))";

	$conn = oci_connect("s74326", "s74326", $db);
	if ($conn)
	{ echo "SUKCES - POLACZONO Z ORACLE\n";
	}else
	{$err= OCIError();
	echo "BLAD POLACZENIA". $ERR[text];
	}
	*/
 }
 function exec($sql){
 
	$this->pdo->beginTransaction();
	if($this->pdo->exec($sql) == true){
		return $this->pdo->commit();
	}else{
		$er = $this->pdo->errorInfo();
		die($er[2]);
		return false;
	}
	
	//$this->pdo->commit();
 }
 function query($sql){
	return $this->pdo->prepare($sql)->execute();
 }
 function QueryGetFetch($sql){
	/*
	$db = $this->pdo->prepare($sql);
	if($db->execute() == true){
		return $db->fetchAll(PDO::FETCH_ASSOC);
	}else
		$er = $this->pdo->errorInfo();
		die($er[2]);
		return false;
	*/
   $this->sql=$sql; 
   $this->rec_position=0; 
  // if($query_str==""){ 
   //   $query_str=$this->query_stmt; 
   //} 
   $this->query = @ociparse($this->connection, $sql); 
   ociexecute($this->query)or die($this->get_error_msg($this->query ,"Query Error : ".$sql)); 
 }
 
 function getErrorsPDO(){
	return $this->pdo->errorCode();
 }	
 
 function getErrorInfoPDO(){
	return $this->pdo->errorInfo();
 }
}

?>